/**
 * Handle changed data.
 *
 * @param {Number} oldValue old value
 * @param {Number} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"86468DA5-D564-4BEA-A0B8-300784D295B0"}
 */
function onDataChange(oldValue, newValue, event) {
	
	var $edited = databaseManager.getEditedRecords()
	var $borro = 0
	for (var i = 0 ; i < $edited.length ; i++)
	{
		var $rcd = $edited[i]
		if ($rcd.precio == 0)
		{
			databaseManager.revertEditedRecords()
			$borro = 1
			break;
		}
	}
	if ($borro == 0)
	{
		databaseManager.saveData()
	}
	
	if (globals.gHabitacion && globals.gTarifa && globals.gTemporada)
	{
		if (globals_to_precios.getSize() == 0)
		{ 
			var $max = ghabitacion_to_tipos_habitacion.limite_adulto
			var $precio = globals_to_precios.getRecord(globals_to_precios.newRecord())
			globals_to_precios.hotel_id 			= globals.gHotelId
			globals_to_precios.precio_adulto_adic 	= 0
			globals_to_precios.precio_menor_adic 	= 0
			for (var i = 1 ; i <= $max ; i++)
			{
				$precio.precios_to_precios_detalle.newRecord(false)
				$precio.precios_to_precios_detalle.cantidad = i
				$precio.precios_to_precios_detalle.precio 	= 0
			}
		}
	}
	return true
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"CD109041-7877-4E15-97D2-EBAFB2778FF6"}
 */
function onShow(firstShow, event) {
	databaseManager.setAutoSave(false)
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"BC722156-A9A0-4D3E-9381-0A5F247A8CA2"}
 */
function onHide(event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	return true
}
